jQuery.fn.extend({
    lazyImage:function(){
        var _self=$(this),
            scrollTop,
            interval,
            lazy=200;
        //判断页面是否发生了滚动
        var scrollWindow=function(){
            var ran=getViewRang();
            if(ran.y!=scrollTop){
                loopLoad(ran);
            }
            //所有图片加载完成,停止事件监听
            if(_self.length>0){
                interval=setTimeout(arguments.callee,lazy);
            }
        };
        //循环队列加载图片
        var loopLoad=function(){
            var temp=[],
                ran=getViewRang();
            _self.each(function(i,n){
                if(isOver(ran,$(this))){
                    temp.push(this);
                    loadImage($(this));
                }
            });
            scrollTop=ran.y;
            //将已读取对象清除出队列
            _self=_self.not(temp);
        }
        //获取视口范围
        var getViewRang=function(){
            return {
                y:$(document).scrollTop(),
                height:$(window).height()
            }
        };
        //是否在视口范围内
        var isOver=function(ran,obj){
            var offset=obj.offset(),                
                objHeight=obj.height(),
                overX=overY=false;
            if(offset.top<(ran.y+ran.height)&&(offset.top+objHeight)>ran.y){
                overY=true;
            }
            return overY;
        };
        //读取真正的图片
        var loadImage=function(obj){
            obj.attr("src",obj.attr("rsrc"));
            return obj;
        }
        scrollWindow();
        return {
            reloadImage:function(){
                loopLoad();
            }
        }
    }
});